/**
 *
 * @param offset {number} 偏移量，前端就是第几页乘以每页多少个 例如 查第二页 称 每页 10条 那 offset 就是 （num-1）* size
 * @param limit {number} 每页的个数
 * @return {string} 限制语句
 */
const parseLimit = (limit, offset) => `limit ${limit} offset ${offset}`
const filterStatement = (statement) => statement

class StatementConfig {
    constructor() {
        this.init()
    }

    init() {

    }

    /**
     *
     * @param TABLE_SCHEMA
     * @param TABLE_NAME
     * @return {string}
     */
    statementGetColumnNameList(TABLE_SCHEMA, TABLE_NAME) {
        return `select COLUMN_NAME
                from information_schema.COLUMNS
                where TABLE_SCHEMA = ${TABLE_SCHEMA}
                  and TABLE_NAME = ${TABLE_NAME}`
    }

    /**
     *
     * @param limit
     * @param offset
     * @return {string}
     */
    statementGetGoodsList(limit, offset) {
        return `select JSON_OBJECT(
                               'total', (select count(*) from songshu.goods),
                               'list', (select JSON_ARRAYAGG(JSON_OBJECT('id', goods_id, 'name', goods_name))
                                        from songshu.goods ${parseLimit(limit, offset)})
                           ) as result`
    }

    /**
     *
     * @param name {String} 用户名 精准查找
     * @return {string}
     */
    statementGetUserInfoByUserNameByLike(name) {
        return `select *
                from songshu.user
                where username like '${name}'`
    }
    statementGetAllUserList(){
        return `select *
                from songshu.user
                where 1 = 1`
    }
}

module.exports = statement = new StatementConfig()
